var t = require;
var e = module;
var o = exports;
var n =
    (this && this.__decorate) ||
    function (t, e, o, n) {
        var i,
            s = arguments.length,
            r = s < 3 ? e : null === n ? (n = Object.getOwnPropertyDescriptor(e, o)) : n;
        if (
            "object" == (typeof Reflect === "undefined" ? "undefined" : typeof Reflect) &&
            "function" == typeof Reflect.decorate
        )
            r = Reflect.decorate(t, e, o, n);
        else
            for (var c = t.length - 1; c >= 0; c--) {
                (i = t[c]) && (r = (s < 3 ? i(r) : s > 3 ? i(e, o, r) : i(e, o)) || r);
            }
        return s > 3 && r && Object.defineProperty(e, o, r), r;
    };
Object.defineProperty(o, "__esModule", { value: !0 }), (o.UIMgr = void 0);
var i = t("SDK"),
    s = t("BaseUI"),
    r = cc._decorator,
    c = (r.ccclass, r.property),
    a = (function () {
        function t() {
            (this.uiLayer = null), (this._prefabs = {}), (this._uis = {}), (this.game = null);
        }
        return (
            (t.prototype.setUILayer = function (t) {
                this.uiLayer = t;
            }),
            (t.prototype.show = function (t, e) {
                if (t != "SplashUI") i.default.showCustomAd();
                var o,
                    n = this;
                this._uis[t]
                    ? ((o = this._uis[t]), this.showUI(t, o, e))
                    : this.getPrefab(t, function (i) {
                        n._uis[t] || ((o = cc.instantiate(i)), (n._uis[t] = o), n.showUI(t, o, e));
                    });
            }),
            (t.prototype.showUI = function (t, e, o) {
                if ((i.default.sendEvent({ key: "openUI", value: { ui: t } }), e.parent))
                    console.log("UI ", t, "已经在视图上");
                else {
                    cc.systemEvent.emit("ui_show", t), this.uiLayer.addChild(e);
                    var n = e.getComponent(s.default);
                    n ? (n.init(o), n.onShow()) : console.log("UIMgr 目标ui不存在对应脚本", t);
                }
            }),
            (t.prototype.hide = function (t, e, o) {
                void 0 === o && (o = !1);
                var n = this._uis[t];
                if (n) {
                    cc.systemEvent.emit("ui_hide", t), n.removeFromParent(!1);
                    var i = n.getComponent(s.default);
                    i ? i.onHide() : console.log("UIMgr 目标ui不存在对应脚本", t),
                        o && (delete this._uis[t], n.destroyAllChildren(), n.destroy());
                }
            }),
            (t.prototype.hideAllUI = function () {
                for (var t = this.uiLayer.children, e = t.length - 1; e >= 0; e--) {
                    this.hide(t[e].name);
                }
            }),
            (t.prototype.getUiByName = function (t) {
                return this._uis[t];
            }),
            (t.prototype.updateData = function (t, e) {
                var o = this._uis[t];
                if (o) {
                    var n = o.getComponent(s.default);
                    n ? n.init(e) : console.log("UIMgr 目标ui不存在对应脚本", t);
                }
            }),
            (t.prototype.preload = function () { }),
            (t.prototype.getPrefab = function (t, e) {
                if (this._prefabs[t]) e(this._prefabs[t]);
                else {
                    var o = this;
                    console.log("加载资源", t),
                        cc.resources.load("ui/" + t, cc.Prefab, function (n, i) {
                            if (n) return console.error(n), void console.error("UI ", t, "不存在ui文件夹下");
                            (o._prefabs[t] = i), e(i);
                        });
                }
            }),
            n([c(cc.Node)], t.prototype, "uiLayer", void 0),
            t
        );
    })(),
    u = (window.UIMgr = new a());
o.UIMgr = u;
